<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
    用户名:<input type="text" name="username" ref="aa1"/><br/>
    用户名2:<input type="text" name="username2" ref="aa2"/><br/>
    <button @click="changeFocus()">切换焦点</button>
</div>

<!--引入vue文件-->
<script type="text/javascript" src="js/vue-2.6.12.js"></script>
<script>
    const v=new Vue({
        el:"#app",
        data:{

        },
        methods:{
            changeFocus(){
                this.$nextTick((x)=>{   //正确写法
                    this.$refs.aa1.focus();
                })
            }
        }
    });
</script>
</body>
</html>